﻿// Copyright (c) 2012 - 2020 Jared Zheng <jaredz at outlook dot com>
// Buddha Framework is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//          http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Create : 2012-12-01 version 0.1 Jared Zheng <jaredz at outlook dot com>
// Update : 2018-12-05 version 3.1.5 Jared Zheng <jaredz at outlook dot com>

#ifndef __BALANCE_PACKET_H__
#define __BALANCE_PACKET_H__

#pragma once

#include "commonpacket.h"

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// 均衡信令定义
enum PAK_EVENT_BALANCE
{
    // 查询授权网关有效地址
    PAKE_BALANCE_AUTHOR = PAKE_BALANCE_BEGIN,  // CTPAKAck<PAKE_BALANCE_AUTHOR, PAKT_EXTERNAL_READY>
    // 查询外网端有效地址
    PAKE_BALANCE_EXTERNAL,                     // CTPAKAck<PAKE_BALANCE_EXTERNAL, PAKT_EXTERNAL_READY>

    PAKE_BALANCE_AUTHORACK = PAKE_BALANCE_ACK, // CPAKAuthorAddrAck   or CPAKAck(error)
    PAKE_BALANCE_EXTERNALACK,                  // CPAKExternalAddrAck or CPAKAck(error)
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///
typedef CTPAKHeadBase<PAKE_BALANCE_AUTHOR, PAKT_EXTERNAL_READY>     CPAKGetAuthorAddr;
typedef CTPAKHeadBase<PAKE_BALANCE_EXTERNAL, PAKT_EXTERNAL_READY>   CPAKGetExternalAddr;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 获取地址
template <UEVENT uEvent, UTYPE uType>
class CTPAKBalanceAddrAck : public CTPAKHeadBase<uEvent, uType>
{
public:
    CTPAKBalanceAddrAck(UACK uAck = (UACK)ERRORD_OKAY);
    virtual ~CTPAKBalanceAddrAck(void);

    CTPAKBalanceAddrAck(const CTPAKBalanceAddrAck& aSrc);
    CTPAKBalanceAddrAck& operator=(const CTPAKBalanceAddrAck& aSrc);

    virtual size_t Length(void) OVERRIDE;
    virtual void   Serialize(CStream&) OVERRIDE;

    CNetAddr&      GetAddr(void);
    void           SetAddr(CNetAddr& Addr);
private:
    CNetAddr       m_Addr;  ///< 地址[ipv4 or ipv6]
};

typedef CTPAKBalanceAddrAck<PAKE_BALANCE_AUTHORACK, PAKT_BALANCE>       CPAKAuthorAddrAck;
typedef CTPAKBalanceAddrAck<PAKE_BALANCE_EXTERNALACK, PAKT_BALANCE>     CPAKExternalAddrAck;

///////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "balancepacket.inl"

#endif // __BALANCE_PACKET_H__
